package io.terminus.lego.shinda.web.security.oauth

import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

/**
 * 替换掉默认的clientRegistrationRepository，从而可以自主定义clientRegistration
 * @author wangmeng
 * @date 2018/4/21
 */

@Configuration
@EnableConfigurationProperties(OAuth2ClientProperties::class)
class OauthConfig constructor(val properties: OAuth2ClientProperties) {
    @Bean
    fun clientRegistrationRepository(): CustomClientRegistrationRepository {
        val registrations = CustomOAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(this.properties).values.toList()
        return CustomClientRegistrationRepository(registrations = registrations)
    }
}